package com.ljq.cls_and_obj;

import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.Scanner;

/**
 * Description:
 * Author:ljq
 * Date:2025-02-16
 * Time:23:09
 */
public class UserRegistration {
    public static void main(String[] args) {
        ArrayList<User> userArr = new ArrayList();
        Scanner scanner = new Scanner(System.in); // 终端输入

        while (true) {
            System.out.println("\n欢迎来到用户注册系统");
            System.out.println("请输入用户名（输入'exit'退出）：");
            String username = scanner.nextLine();

            if ("exit".equalsIgnoreCase(username)) {
                System.out.println("退出注册系统。");
                break;
            }

            System.out.println("请输入手机号：");
            String phoneNumber = scanner.nextLine();

            String password = "";
            String confirmPassword = "";
            boolean passwordsMatch = false;
            while (!passwordsMatch){
                System.out.println("请输入登录密码：");
                password = scanner.nextLine();
                System.out.println("请再次确认密码：");
                confirmPassword = scanner.nextLine();
                if (!password.equals(confirmPassword)) {
                    System.out.println("两次输入的密码不一致，请重新输入！");
                } else {
                    passwordsMatch = true;
                }
            }

            System.out.println("请输入电子邮箱：");
            String email = scanner.nextLine();

            System.out.println("请输入性别（男/女）：");
            String gender = scanner.nextLine();
            System.out.println("请输入生日（格式：yyyy-MM-dd）：");
            String birthdayInput = scanner.nextLine();
            DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
            LocalDate birthday = LocalDate.parse(birthdayInput, dateTimeFormatter);

            // 创建用户对象并添加到集合中
            User newUser = new User(username, phoneNumber, password, confirmPassword, email, gender, birthday);
            userArr.add(newUser);

            System.out.println("用户注册成功！");
            System.out.println("当前注册的用户信息：");
            for (User user : userArr) {
                System.out.println(user);
            }

        }
        scanner.close();
    }
}
